//
//  YXConstant.m
//  HotalProject
//
//  Created by jun on 2017/10/24.
//  Copyright © 2017年 dw. All rights reserved.
//

#import "YXConstant.h"

NSString * const TAG_TOKEN = @"TAG_TOKEN";
NSString * const TAG_INDUSTRY_TYPE = @"TAG_INDUSTRY_TYPE";
NSString * const TAG_ELECTRICITY_TYPE = @"TAG_ELECTRICITY_TYPE";
NSString * const TAG_CONFIG_SEARCHPRICELIST = @"tag_config_search_price_list";

@implementation YXConstant

+(NSString*)nowMonthDay{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *nowdate = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:nowdate];
    
    NSDate *beginningOfWeek = [calendar dateFromComponents:components];
    
    return [dateFormatter stringFromDate:beginningOfWeek];;
}

+(NSString*)lastMonthDay{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *nowdate = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:nowdate];
    NSInteger month = [components month] - 1;
    
    [components setMonth:month];
    NSDate *beginningOfWeek = [calendar dateFromComponents:components];
    return [dateFormatter stringFromDate:beginningOfWeek];
}

+(NSString*)lastNumDay:(NSUInteger)num{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *nowdate = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:nowdate];
    NSInteger day = [components day] - num;
    
    [components setDay:day];
    NSDate *beginningOfWeek = [calendar dateFromComponents:components];
    return [dateFormatter stringFromDate:beginningOfWeek];
}

+(NSString*)date2String:(NSDate*)date{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:date];
    return [NSString stringWithFormat:@"%ld-%ld-%ld",(long)[components year],(long)[components month],(long)[components day]];
}

+(NSString*)getDay:(NSString*)date{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *stDate =[dateFormatter dateFromString:date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:stDate];
    return [NSString stringWithFormat:@"%ld月%ld日",(long)[components month],(long)[components day]];
}

+ (NSString *)fileSizeWithInterge:(NSInteger)size{
    // 1k = 1024, 1m = 1024k
    if (size < 1024) {// 小于1k
        return [NSString stringWithFormat:@"%ldB",(long)size];
    }else if (size < 1024 * 1024){// 小于1m
        CGFloat aFloat = size/1024;
        return [NSString stringWithFormat:@"%.0fK",aFloat];
    }else if (size < 1024 * 1024 * 1024){// 小于1G
        CGFloat aFloat = size/(1024 * 1024);
        return [NSString stringWithFormat:@"%.1fM",aFloat];
    }else{
        CGFloat aFloat = size/(1024*1024*1024);
        return [NSString stringWithFormat:@"%.1fG",aFloat];
    }
}

//+(NSData *)imageData:(UIImage *)myimage{
//    NSData *data=UIImageJPEGRepresentation(myimage, 1.0);
//    if (data.length>100*1024) {
//        if (data.length>1024*1024) {
//            //1M以及以上
//            data=UIImageJPEGRepresentation(myimage, 0.1);
//        }else if (data.length>512*1024) {
//            //0.5M-1M
//            data=UIImageJPEGRepresentation(myimage, 0.5);
//        }else if (data.length>200*1024) {
//            //0.25M-0.5M
//            data=UIImageJPEGRepresentation(myimage, 0.9);
//        }
//    }
//    return data;
//}
    

@end
